var username = getCookie('username')
if(!username){
    layer.mag('请先登录',{
        icon:2,
        time:1000
    },function(){
        location.href = '首页.html?callback='+location.href
    })
}
$.ajax({
    url: 'http://localhost:8888/cart/list',
    data: {
        id: getCookie('userId')
    },
    headers: {
        authorization: localStorage.getItem('token') || ''
    }
}).then(res => {
    console.log(res);
    if(res.code === 1){
        if(!res.cart.length){
            showEmpty()
            return false
        }
        var html = ''
        res.cart.forEach((item, index) => {
            html += `
            <div class="car_body_row3">
                            <div class="car_body_checkbox" data-id="${item.goods_id}">
                                <input type="checkbox" class="checkOne" ${item.is_select ? 'checked' : ''}>
                            </div>
                            <div class="car_body_img">
                                <img src="${item.img_small_logo}" alt="">
                            </div>  
                            <div class="car_body_goods">                          
                                <b></b>
                                <p><a>${item.title}</a></p>                          
                            </div> 
                            <div class="car_body_style"></div>                       
                            <div class="car_body_price">¥<span>${item.price}</span>元</div>
                            <div class="car_body_num" data-stock="${item.goods_number}" data-id="${item.goods_id}">
                                <input type="button" value="-" class="reduce">
                                <input type="number" value="${item.cart_number}" class="goodsNumber">
                                <input type="button" value="+" class="add">
                                <p>有货</p>
                            </div>
                            <div class="car_body_sum">¥<span>${item.price * item.cart_number}</span>
                            </div>
                            <div class="car_body_operate">
                                <p>
                                    <a href="javaScript:;" class="del" data-id="${item.goods_id}">删除</a>
                                    <a href=""></a>
                                </p>
                            </div>
                        </div>
            `
        })
        $('.cent').html(html)
    }
})